<?php
/**
 * Created by PhpStorm.
 * User: venki
 * Date: 2023/12/16
 * Time: 12:24
 */

namespace app\modelFilter;

use Yii;
use yii\base\Model;
use app\models\PurchaseOrder;
use yii\data\ActiveDataFilter;
use yii\data\ActiveDataProvider;

class PurchaseOrdersFilter extends Model
{
    public function filter()
    {
        $filter = new ActiveDataFilter(['searchModel' => PurchaseOrder::class]);

        $filterCondition = null;

        // 您可以从任何来源加载过滤器。例如：
        // 如果你更喜欢请求体中的 JSON，
        // 使用 Yii::$app->request->getBodyParams() 如下：
        if ($filter->load(Yii::$app->request->get())) {
            $filterCondition = $filter->build();
            if ($filterCondition === false) {
                // Serializer would get errors out of it
                return $filter;
            }
        }

        $query = PurchaseOrder::find();
        if ($filterCondition !== null) {
            $query->andWhere($filterCondition);
        }

        return new ActiveDataProvider([
            'query' => $query,
        ]);
    }

    public function name()
    {
    }

    public function no()
    {

    }
}